#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define STR_BUF 81
#define MAX_PERSON 20

typedef struct {
    char name[STR_BUF];
    char department[STR_BUF];
    bool valid;
    int count;
} Person;

Person g_data[MAX_PERSON] = { 0 };
int g_num = 0;

void recordPerson(char* name, char* dep)
{
    for (int i = 0; i < g_num; i++) {
        if (strcmp(name, g_data[i].name) == 0) {
            g_data[i].valid = false;
            return;
        }
    }

    strcpy(g_data[g_num].name, name);
    strcpy(g_data[g_num].department, dep);
    g_data[g_num].valid = true;
    g_data[g_num].count = 0;
    g_num++;
}

void recordCount(char* name)
{
    for (int i = 0; i < g_num; i++) {
        if (strcmp(name, g_data[i].name) == 0 && g_data[i].valid) {
            g_data[i].count++;
            return;
        }
    }
}

int cmp(const void* a, const void* b)
{
    Person* pa = (Person*)a;
    Person* pb = (Person*)b;
    if (pa->valid != pb->valid) {
        return pb->valid - pa->valid;
    }
    return pb->count - pa->count;
}

void show(void)
{
    printf("%20s|%20s|%6s|%5s|\n", "name", "dep", "valid", "count");
    for (int i = 0; i < g_num; i++) {
        printf("%20s|%20s|%6d|%5d|\n", g_data[i].name, g_data[i].department, g_data[i].valid, g_data[i].count);
    }
    printf("\n");
}

int main(int argc, char const* argv[])
{
    freopen("./in.txt", "r", stdin);

    int personNum = 0;
    if (scanf("%d", &personNum) != 1) {
        return 0;
    }
    getchar();

    char name[STR_BUF];
    char department[STR_BUF];
    for (int i = 0; i < personNum; i++) {
        if (gets(name) == NULL) {
            return 0;
        }
        if (gets(department) == NULL) {
            return 0;
        }
        recordPerson(name, department);
    }

    int count = 0;
    if (scanf("%d", &count) != 1) {
        return 0;
    }
    getchar();

    for (int i = 0; i < count; i++) {
        if (gets(name) == NULL) {
            return 0;
        }
        recordCount(name);
    }

    if (g_num == 0) {
        printf("tie");
        return 0;
    }

    qsort(g_data, g_num, sizeof(Person), cmp);

    if (g_num == 0) {
        printf("tie");
        return 0;
    }

    if (!g_data[0].valid) {
        printf("tie");
        return 0;
    }

    if (g_data[0].count == g_data[1].count && g_data[0].valid && g_data[1].valid) {
        printf("tie");
        return 0;
    }

    printf("%s", g_data[0].department);

    return 0;
}